package com.tf_cut.backend.seller.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.Lists;
import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.common.pojo.Result;
import com.tf_cut.backend.platform.vo.RechargeVo;
import com.tf_cut.backend.seller.service.SellerBillService;
import com.tf_cut.backend.seller.service.SellerService;
import com.tf_cut.backend.seller.vo.SellerBillAndConsigneeVo;
import com.tf_cut.backend.seller.vo.SellerOrderVo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/backend/admin/seller/bill")
@Slf4j
public class SellerBillController {

    @Autowired
    private SellerService sellerService;

    @Autowired
    private SellerBillService sellerBillService;

    @RequestMapping("/list")
    public String querySellerBillList(String json) {
        SellerBillAndConsigneeVo sellerBillAndConsigneeVo = JSON.parseObject(json, SellerBillAndConsigneeVo.class);
        Result<List<SellerBillAndConsigneeVo>> result;
        try {
            PageInfo<SellerBillAndConsigneeVo> sellerBillAndConsigneeVoPageInfo = sellerBillService.querySellerBillList(sellerBillAndConsigneeVo);
            return JSON.toJSONString(sellerBillAndConsigneeVoPageInfo, SerializerFeature.WriteDateUseDateFormat);
        } catch (Exception e) {
            log.error("querySellerBillList error:{}", e.getMessage(), e);
            result = Result.of(Lists.newArrayList());
            result.setMsg(e.getMessage());
            result.setFlag(false);
        }
        return JSON.toJSONString(result, SerializerFeature.WriteDateUseDateFormat);
    }
    
    
    /**
     * 在admin包platform包下的GrantController类下的queryBilling方法
     * @param page
     * @param rows
     * @param sellerName
     * @param serviceName
     * @param startDate
     * @param endDate
     * @return
     */
    @RequestMapping("/queryBilling")
    public String queryBilling(@RequestParam("page") int page,@RequestParam("rows") int rows,@RequestParam("sellerCompanyName") String sellerCompanyName,
    		@RequestParam("status") String status,@RequestParam("startDate") String startDate,
            @RequestParam("endDate") String endDate) {
    	PageInfo<SellerBillAndConsigneeVo> sellerBillAndConsigneeVoPageInfo = sellerBillService.queryBilling(page,rows,sellerCompanyName,status,startDate,endDate);
    	return JSON.toJSONString(sellerBillAndConsigneeVoPageInfo, SerializerFeature.WriteDateUseDateFormat);
    }
    
	@RequestMapping("findBybill")
	public List<SellerBillAndConsigneeVo> findBybill(@RequestParam("sellerCompanyName") String sellerCompanyName,
    		@RequestParam("status") String status,@RequestParam("startDate") String startDate,
            @RequestParam("endDate") String endDate){
		
		return sellerBillService.findBybill(sellerCompanyName,status,startDate,endDate);
	}
}
